const gulp = require("gulp");
const uglify = require("gulp-uglify");
const webserver = require("gulp-webserver");
const sass = require("gulp-sass");
const babel = require("gulp-babel");

gulp.task("server",["static"], ()=>{
	gulp.src("dist")
		.pipe(webserver({
			
			livereload: true,
			proxies: [
				{
					source: "./api",
					target: "http://www.hxyxt.com/_ui/desktop/common/images/onesite/newYXT2017/json/",
				}
			]
		}))
	gulp.watch("src/pages/**/*.js",["compileJS"]);
	gulp.watch("src/scripts/**/*.js",["compileJS"]);
	gulp.watch("src/conf/**/*.js",["compileJS"]);
	gulp.watch("src/pages/**/*.html",["compileHTML"]);
	gulp.watch("src/styles/**/*.scss",["compileCSS"]);
})

gulp.task("compileHTML",()=>{
	gulp.src("src/pages/**/*.html")
		.pipe(gulp.dest("dist/pages/"))
})
gulp.task("compileJS",()=>{
	gulp.src("src/pages/**/*.js")
		// .pipe(babel({
		// 	presets: ['@babel/env']
		// }))
		// .pipe(uglify())
		.pipe(gulp.dest("dist/pages/"))
	gulp.src("src/conf/**/*.js")
		// .pipe(babel({
		// 	presets: ['@babel/env']
		// }))
		// .pipe(uglify())
		.pipe(gulp.dest("dist/conf/"))
	gulp.src("src/scripts/**/*.js")
		// .pipe(babel({
		// 	presets: ['@babel/env']
		// }))
		// .pipe(uglify())
		.pipe(gulp.dest("dist/scripts/"))
})
gulp.task("static",()=>{
	gulp.src("src/static/**/*.*")
		.pipe(gulp.dest("dist/static/"))
})

gulp.task("compileCSS",()=>{
	gulp.src("src/styles/**/*.scss")
		.pipe(sass().on('error', sass.logError))
		.pipe(gulp.dest("dist/styles/"))
})